﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 纺织贸易管理系统;

namespace Update
{
  public  class UpdateHelper
    {
        /// <summary>
        /// 新增菜单
        /// </summary>
        /// <param name="menu"></param>
        public static void AddMenu(MenuTable menu)
        {
            //var kcconnect = new SQLHelper.SQLHelper("Server=softkc.cn,1433;uid=sa;pwd=Kc123456;database=FinishDB");
            var db = Connect.GetSugar();
            foreach (var user in db.Queryable<Yhb>().ToList())
            {
                if (db.Queryable<MenuTable>().First(x => x.MenuName == menu.MenuName&&x.UserID==user.YHBH) == null)
                {
                    menu.Visitable = true;
                    menu.UserID = user.YHBH;
                    db.Insertable<MenuTable>(menu).ExecuteCommand();
                }
            }
        }
        //新增表格
        public static void AddColumn(string FormName,string GridviewName)
        {
            var kcconnect = new SQLHelper.SQLHelper("Server=softkc.cn;uid=sa;pwd=Kc123456;database=FinishDB");
            var db = Connect.GetSugar();
            foreach (var user in db.Queryable<Yhb>().ToList())
            {
                if (db.Queryable<ColumnTable>().First(x => x.FormName == FormName) == null)
                {
                    List<ColumnTable> columns = new List<ColumnTable>();
                    if (string.IsNullOrEmpty(GridviewName))
                    {
                        columns = kcconnect.Query<ColumnTable>(x => x.FormName == FormName);
                    }
                    else
                    {
                        columns = kcconnect.Query<ColumnTable>(x => x.FormName == FormName && x.GridName == GridviewName);
                    }
                    columns.ForEach(x => x.UserID = user.YHBH);
                    db.Insertable<ColumnTable>(columns).ExecuteCommand();
                }
            }
        }
    }
}
